package com.awise.app.more.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import com.awise.R;
import com.awise.base.BaseActivity;

import java.util.Timer;
import java.util.TimerTask;


/**
 * Created by lgz on 2018/1/23.
 */

public class EditNameActivity extends BaseActivity implements View.OnClickListener {
    private EditText edit_name_et_name;
    Timer timer = new Timer();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.more_edit_name_layout);
        initView();

    }

    private void initView() {
        TextView s_back = (TextView) this.findViewById(R.id.tv_back);
        s_back.setVisibility(View.VISIBLE);
        s_back.setOnClickListener(this);
        TextView tv_save = (TextView) this.findViewById(R.id.tv_save);
        tv_save.setVisibility(View.VISIBLE);
        tv_save.setOnClickListener(this);
        TextView textView_content = (TextView) this.findViewById(R.id.textView_content);
        textView_content.setText(R.string.change_name_msg);
        edit_name_et_name = (EditText) this.findViewById(R.id.edit_name_et_name);
        edit_name_et_name.setOnClickListener(this);
        timer.schedule(new TimerTask() {
            public void run() {
                InputMethodManager inputManager =
                        (InputMethodManager)edit_name_et_name.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(edit_name_et_name, 0);
            }
        },300);
      /*  edit_name_et_name.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });*/
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_back:
                finish();
                break;
            case R.id.edit_name_et_name:

                break;
            case R.id.tv_save:
                Intent intent = new Intent();
                 String name= edit_name_et_name.getText()+"";
                intent.putExtra("name",name);
                setResult(RESULT_OK,intent);
                finish();
                break;
        }
    }

   /* private void setEditable(EditText editText, int maxLength, boolean value) {
        if (value) {
            editText.setFilters(new InputFilter[] { new MyEditFilter(maxLength) });
            editText.setCursorVisible(true);
            editText.setFocusableInTouchMode(true);
            editText.requestFocus();
        } else {
            editText.setFilters(new InputFilter[] { new InputFilter() {
                @Override
                public CharSequence filter(CharSequence source, int start,
                                           int end, Spanned dest, int dstart, int dend) {
                    return source.length() < 1 ? dest.subSequence(dstart, dend)
                            : "";
                }
            } });
            editText.setCursorVisible(false);
            editText.setFocusableInTouchMode(false);
            editText.clearFocus();
        }
    }*/
}
